<!DOCTYPE HTML>
<html>
<head>
	<?php include("include.php");
	
	//get an id
	$eventID = (empty($_POST['eventID']))?1:mysql_real_escape_string($_POST['eventID']);
	//echo $eventID; die();
	
	//Check whether we are updating or not
	$update = (empty($_POST['update']))?1:mysql_real_escape_string($_POST['update']);
	//echo $eventID;
	if($update=="true"){
		//GET UPDATED VALUES AND UPDATE THE DB
		$uName = (empty($_POST['eventname']))?1:mysql_real_escape_string($_POST['eventname']);
		$uLocation = (empty($_POST['location']))?1:mysql_real_escape_string($_POST['location']);
		$uHost = (empty($_POST['host']))?1:mysql_real_escape_string($_POST['host']);
		$uDesc = (empty($_POST['description']))?1:mysql_real_escape_string($_POST['description']);
		$uStart = (empty($_POST['start']))?1:mysql_real_escape_string($_POST['start']);
		$uEnd = (empty($_POST['end']))?1:mysql_real_escape_string($_POST['end']);
		$uImage = (empty($_POST['image']))?1:mysql_real_escape_string($_POST['image']);
		$uLink = (empty($_POST['link']))?1:mysql_real_escape_string($_POST['link']);
		//echo $uName;
		//echo $eventID; die();
		$sql = "UPDATE Events SET NAME = '$uName' WHERE ID = '$eventID';
				UPDATE Events SET LOCATION = '$uLocation' WHERE ID = '$eventID';
				UPDATE Events SET HOSTED_BY = '$uHost' WHERE ID = '$eventID';
				UPDATE Events SET DESCRIPTION = '$uDesc' WHERE ID = '$eventID';
				UPDATE Events SET START_TIME = '$uStart' WHERE ID = '$eventID';
				UPDATE Events SET END_TIME = '$uEnd' WHERE ID = '$eventID';
				UPDATE Events SET IMAGE_PATH = '$uImage' WHERE ID = '$eventID';
				UPDATE Events SET LINK = '$uLink' WHERE ID = '$eventID'; 
				";
		//echo $sql; die();
		//$sql = "UPDATE Events SET NAME = 'Protest' WHERE ID = $ID";
		database::insertSQL($sql);
		
	}
	//get event from id
	$event = eventClass::getEventDetails($eventID);
	//echo $event['NAME'];
	
	?>
	
	<style>
		#content label{ display:inline-block;width:90px; }
		#content label.error{ width:200px; margin-left:95px; display:block; color:red; }
	</style>
	
</head>
<body>

<div class="container">
	<div id="header">
		<?php include("banner.php")?>
		
		<div id="login">
			<?php login::displayLoginDiv(); ?>
		</div>
		
		<div class="clear"></div>
		
		<div id="navigation">
			<?php include('navigation.php'); ?>
		</div>
	</div>
	
	<div class="clear"></div>
	
	<div id="body">
		<div id="content">
			<h1>Edit Event</h1>
			
			<form action="editevent.php" method="post" id="editEventForm">
				<label for="username">Event Name:</label>
					<input id="eventname" type="text" class="text required" name="eventname" value="<?php echo $event['NAME']; ?>"/>
					<br/>
				<label for="location">Location:</label>
					<input id="location" type="text" class="text required" name="location" value="<?php echo $event['LOCATION']; ?>"/>
					<br/>
				<label for="host">Hosted By:</label>
					<input id="host" type="text" class="text required" name="host" value="<?php echo $event['HOSTED_BY']; ?>"/>
					<br/>
				<label for="description" style="float:left; margin-right:4px;">Description:</label>
					<textarea id="description" class="text required" name="description" cols="65" rows="10" ><?php echo $event['DESCRIPTION']; ?></textarea>
					<br/>
				<label for="start">Start Time:</label>
					<input id="start" type="text" class="text required" name="start" value="<?php echo $event['START_TIME']; ?>"/>
					<br/>
				<label for="end">End Time:</label>
					<input id="end" type="text" class="text required" name="end" value="<?php echo $event['END_TIME']; ?>"/>
					<br/>
				<label for="image">Image URL:</label>
						<input id="image" type="text" class="text required" name="image" value="<?php echo $event['IMAGE_PATH']; ?>"/>
						<br/>
				<label for="link">Link:</label>
					<input id="link" type="text" class="text" name="link" value="<?php echo $event['LINK']; ?>"/>
					<br/>
					
				<br/>
				<input type="hidden" name="update" value="true">
				<input type="hidden" name="eventID" value="<?php echo $eventID;?>">
				<input type="submit" class="submit" value="Save">
			</form>
			
			<script>
				$("#editEventForm").validate();
			</script>
			
			
		</div>
		<div id="tags">
			<h1>Tags</h1>
			<?php tag::displayTagCloud(); ?>
		</div>
	
	</div>
	
	<div class="clear"></div>
	
	<div id="footer">
		<?php include("footer.php"); ?>
	</div>

</div>


</body>
</html>